package com.yixiu.study.juc.lock;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @CalssName T02_ReenTrantLock2
 * @Description
 * @Author yixiu
 * @Date 2021/6/24 9:53
 * @Verison num1.0
 **/
public class T02_ReenTrantLock2 extends Thread{

    private static ReentrantLock lock = new ReentrantLock(true);

    @Override
    public void run(){
        for(int i=0; i<1; i++){
            lock.lock();
            try {
                System.out.println(Thread.currentThread().getName() + "获得锁");
            } finally {
                lock.unlock();
            }
        }
    }

    public static void main(String[] args) {
        T02_ReenTrantLock2 r1 = new T02_ReenTrantLock2();
//        List<Thread> threadList = new ArrayList<>();
//        for(int i=0; i<100; i++){
//            threadList.add(new Thread(r1));
//        }
//
//        threadList.forEach(th -> th.start());

        for(int i=0; i<100; i++){
            new Thread(r1).start();
        }


//        Thread t1 = new Thread(r1);
//        Thread t2 = new Thread(r1);
//        t1.start();
//        t2.start();
    }


}
